package poker;

import static org.junit.Assert.*;

//import org.junit.Before;
import org.junit.Test;

public class HandTest {
	
	private int ace = 1, king = 13, queen = 12, jack = 11,
			heart = 1, spade = 2, diamond = 3, club = 4;
	Hand h1, h2;
	Deck d = new Deck();
	
  @Test
  public void testogolny() {
	h1 = new Hand(d);
	h2 = new Hand(d);
	h1.evaluate();
	h2.evaluate();
    assertSame(h1.compareTo(h1), 0);
    assertNotSame(h1.compareTo(h2), h2.compareTo(h1));
    assertSame(h1.compareTo(h2), -h2.compareTo(h1));
  }

  
  @Test
  public void Porownajuklady() {
	
	//pair  > high card 		2 2 queen jack 10 > ace king queen jack 9
	h1 = new Hand(new Card(heart,2),new Card(club,2),new Card(heart,queen),new Card(heart,jack),new Card(heart,10));
	h2 = new Hand(new Card(club,ace),new Card(spade,king),new Card(spade,queen),new Card(spade,jack),new Card(spade,9));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje uklady[1]", h1.compareTo(h2), 1);	
	
	//two pairs  > pair  	2 2 3 3 jack  > 3 3 ace king queen 
	h1 = new Hand(new Card(heart,2),new Card(club,2),new Card(heart,3),new Card(club,3),new Card(heart,jack));
	h2 = new Hand(new Card(diamond,3),new Card(spade,3),new Card(spade,queen),new Card(spade,jack),new Card(spade,ace));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje uklady[2]", h1.compareTo(h2), 1);	
	
	//three of kind > two pairs    2 2 2 4 jack > ace ace king king 10
	h1 = new Hand(new Card(heart,2),new Card(club,2),new Card(spade,2),new Card(club,4),new Card(heart,jack));
	h2 = new Hand(new Card(diamond,ace),new Card(spade,ace),new Card(spade,king),new Card(spade,king),new Card(spade,10));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje uklady[3]", h1.compareTo(h2), 1);	
	
	//straight > three of kind
	h1 = new Hand(new Card(heart,2),new Card(club,3),new Card(spade,4),new Card(club,5),new Card(heart,6));
	h2 = new Hand(new Card(diamond,ace),new Card(spade,ace),new Card(spade,ace),new Card(spade,king),new Card(spade,10));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje uklady[4]", h1.compareTo(h2), 1);
	
	//flush > straight
	h1 = new Hand(new Card(heart,2),new Card(heart,3),new Card(heart,7),new Card(heart,9),new Card(heart,jack));
	h2 = new Hand(new Card(diamond,ace),new Card(spade,king),new Card(spade,queen),new Card(spade,jack),new Card(spade,10));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje uklady[5]", h1.compareTo(h2), 1);
	
	//full house > three of kind
	h1 = new Hand(new Card(heart,2),new Card(club,2),new Card(spade,2),new Card(club,4),new Card(heart,4));
	h2 = new Hand(new Card(diamond,ace),new Card(spade,ace),new Card(club,ace),new Card(spade,king),new Card(spade,10));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje uklady[6]", h1.compareTo(h2), 1);
	
	//full house > straight
	h1 = new Hand(new Card(heart,2),new Card(club,2),new Card(spade,2),new Card(club,4),new Card(heart,4));
	h2 = new Hand(new Card(diamond,ace),new Card(spade,king),new Card(spade,queen),new Card(spade,jack),new Card(spade,10));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje uklady[7]", h1.compareTo(h2), 1);
	
	//four of kind > flush
	h1 = new Hand(new Card(heart,2),new Card(club,2),new Card(spade,2),new Card(diamond,2),new Card(heart,jack));
	h2 = new Hand(new Card(diamond,ace),new Card(diamond,king),new Card(diamond,queen),new Card(diamond,jack),new Card(diamond,7));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje uklady[8]", h1.compareTo(h2), 1);
	
	//four of kind > full house
	h1 = new Hand(new Card(heart,2),new Card(club,2),new Card(spade,2),new Card(diamond,2),new Card(heart,jack));
	h2 = new Hand(new Card(diamond,ace),new Card(club,ace),new Card(diamond,queen),new Card(club,queen),new Card(spade,queen));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje uklady[9]", h1.compareTo(h2), 1);
	
	//poker > full house
	h1 = new Hand(new Card(spade,ace),new Card(spade,king),new Card(spade,queen),new Card(spade,jack),new Card(spade,10));
	h2 = new Hand(new Card(diamond,ace),new Card(spade,king),new Card(spade,queen),new Card(spade,jack),new Card(spade,10));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje uklady[10]", h1.compareTo(h2), 1);
	
	//poker > straight
	h2 = new Hand(new Card(heart,ace),new Card(heart,king),new Card(heart,queen),new Card(heart,jack),new Card(club,10));
	h2.evaluate();
	assertEquals("Zle porownuje uklady[11]", h1.compareTo(h2), 1);
	
	//poker > flush
	h2 = new Hand(new Card(heart,ace),new Card(heart,king),new Card(heart,queen),new Card(heart,jack),new Card(heart,9));
	h2.evaluate();
	assertEquals("Zle porownuje uklady[12]", h1.compareTo(h2), 1);
  }
  
  
  
  @Test
  public void highcard() {
	
	//ace > king
	h1 = new Hand(new Card(heart,ace),new Card(spade,8),new Card(diamond,7),new Card(heart,4),new Card(heart,2));
	h2 = new Hand(new Card(heart,king),new Card(spade,8),new Card(diamond,7),new Card(heart,4),new Card(heart,2));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle wysoka karte [1]",h1.compareTo(h2), 1);	
	  
	// ace king queen jack 9 > ace king queen jack 8  
	h1 = new Hand(new Card(heart,ace),new Card(spade,king),new Card(diamond,queen),new Card(heart,jack),new Card(heart,9));
	h2 = new Hand(new Card(heart,ace),new Card(spade,king),new Card(diamond,queen),new Card(heart,jack),new Card(heart,8));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle wysoka karte [2]",h1.compareTo(h2), 1);
	
	//ace king 5 3 2 > ace king 4 3 2
	h1 = new Hand(new Card(heart,ace),new Card(spade,king),new Card(diamond,5),new Card(heart,3),new Card(heart,2));
	h2 = new Hand(new Card(heart,ace),new Card(spade,king),new Card(diamond,4),new Card(heart,3),new Card(heart,2));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle wysoka karte [3]",h1.compareTo(h2), 1);
  }
  

  @Test
  public void pair() {
	
	//ace ace  4 3 2 > king king 4 3 2
	h1 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,4),new Card(heart,3),new Card(heart,2));
	h2 = new Hand(new Card(heart,king),new Card(spade,king),new Card(diamond,4),new Card(heart,3),new Card(heart,2));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje pare [1]",h1.compareTo(h2), 1);	
	  
	//ace ace  5 3 2 > ace ace  4 3 2
	h1 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,5),new Card(heart,3),new Card(heart,2));
	h2 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,4),new Card(heart,3),new Card(heart,2));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje pare [2]", h1.compareTo(h2), 1);	
  }
 
  @Test
  public void twopairs() {
	
	//ace ace  4 4 2 > king king 4 4 2
	h1 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,4),new Card(heart,4),new Card(heart,2));
	h2 = new Hand(new Card(heart,king),new Card(spade,king),new Card(diamond,4),new Card(heart,4),new Card(heart,2));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje dwie pary [1]", h1.compareTo(h2), 1);	
	  
	//ace ace  4 4 2 > ace ace 3 3 2
	h1 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,4),new Card(heart,4),new Card(heart,2));
	h2 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,3),new Card(heart,3),new Card(heart,2));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje dwie pary [2]", h1.compareTo(h2), 1);	
	
	//ace ace  4 4 3 > ace ace 4 4 2
	h1 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,4),new Card(heart,4),new Card(heart,3));
	h2 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,4),new Card(heart,4),new Card(heart,2));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje dwie pary [3]", h1.compareTo(h2), 1);	
  }
  
  @Test
  public void threeofakind() {
	
	//ace ace  ace 4 2 > king king king 4 2
	h1 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,ace),new Card(heart,4),new Card(heart,2));
	h2 = new Hand(new Card(heart,king),new Card(spade,king),new Card(diamond,king),new Card(heart,4),new Card(heart,2));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje trojki [1]", h1.compareTo(h2), 1);	
  }
  
  @Test
  public void straight() {

	//ace king queen jack 10 > king queen jack 10 9
	h1 = new Hand(new Card(heart,ace),new Card(spade,king),new Card(diamond,queen),new Card(heart,jack),new Card(heart,10));
	h2 = new Hand(new Card(heart,king),new Card(spade,queen),new Card(diamond,jack),new Card(heart,10),new Card(heart,9));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje straight [1]", h1.compareTo(h2), 1);
  }
  
  @Test
  public void flush() {
	
	//(ace king queen jack 9) of hearts == (ace king queen jack 10) of spades
	h1 = new Hand(new Card(heart,ace),new Card(heart,king),new Card(heart,queen),new Card(heart,jack),new Card(heart,9));
	h2 = new Hand(new Card(spade,ace),new Card(spade,king),new Card(spade,queen),new Card(spade,jack),new Card(spade,9));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje flush [1]", h1.compareTo(h2), 0);	
	
	//(ace 6 5 4 3) of hearts > ( king queen jack 10 8) of hearts
	h1 = new Hand(new Card(heart,ace),new Card(heart,6),new Card(heart,5),new Card(heart,4),new Card(heart,3));
	h2 = new Hand(new Card(heart,king),new Card(heart,queen),new Card(heart,jack),new Card(heart,10),new Card(heart,8));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje flush [2]", h1.compareTo(h2), 1);	
  }
  
  @Test
  public void fullhouse() {
	
	//ace ace ace king king > ace ace ace queen queen ( IMMPOSIBLE IN FIVE CARD DRAW :D)
	h1 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,ace),new Card(spade,king),new Card(heart,king));
	h2 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,ace),new Card(spade,queen),new Card(heart,queen));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje full house [1]", h1.compareTo(h2), 1);	
	
	//ace ace ace king king > ace ace king king king  ( IMMPOSIBLE IN FIVE CARD DRAW :D)
	h1 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,ace),new Card(spade,king),new Card(heart,king));
	h2 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,king),new Card(spade,king),new Card(heart,king));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje full house [2]", h1.compareTo(h2), 1);	
	
	//ace ace king king king > ace ace queen queen queen
	h1 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,king),new Card(spade,king),new Card(heart,king));
	h2 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,queen),new Card(spade,queen),new Card(heart,queen));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje full house [3]", h1.compareTo(h2), 1);	
  }
  
  @Test
  public void fourofkind() {
	
	//ace ace ace ace king > ace ace ace ace queen ( IMMPOSIBLE IN FIVE CARD DRAW :D)
	h1 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,ace),new Card(club,ace),new Card(heart,king));
	h2 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,ace),new Card(club,ace),new Card(heart,queen));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje four of king [1]", h1.compareTo(h2), 1);	
	
	//ace ace ace ace  queen > king king king king queen
	h1 = new Hand(new Card(heart,ace),new Card(spade,ace),new Card(diamond,ace),new Card(club,ace),new Card(heart,queen));
	h2 = new Hand(new Card(heart,king),new Card(spade,king),new Card(diamond,king),new Card(club,king),new Card(spade,queen));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje four of kind [2]", h1.compareTo(h2), 1);	
	
  }
  
  @Test
  public void poker() {
	
	//(ace king queen jack 10) of heart == (ace king queen jack 10) of spades 
	h1 = new Hand(new Card(heart,ace),new Card(heart,king),new Card(heart,queen),new Card(heart,jack),new Card(heart,10));
	h2 = new Hand(new Card(spade,ace),new Card(spade,king),new Card(spade,queen),new Card(spade,jack),new Card(spade,10));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje poker [1]", h1.compareTo(h2), 0);	
	
	//(ace king queen jack 10) of heart > (king queen jack 10 9) of spades 
	h1 = new Hand(new Card(heart,ace),new Card(heart,king),new Card(heart,queen),new Card(heart,jack),new Card(heart,10));
	h2 = new Hand(new Card(spade,king),new Card(spade,queen),new Card(spade,jack),new Card(spade,10),new Card(spade,9));
	h1.evaluate();
	h2.evaluate();
	assertEquals("Zle porownuje poker [2]", h1.compareTo(h2), 1);	
  }
}
